package cn.iocoder.yudao.module.member.controller.app.job;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.member.controller.admin.job.vo.AppJobRespVO;
import cn.iocoder.yudao.module.member.controller.admin.job.vo.JobPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.job.vo.JobRespVO;
import cn.iocoder.yudao.module.member.controller.admin.job.vo.JobSaveReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.job.ApiJobDO;
import cn.iocoder.yudao.module.member.dal.dataobject.jobintention.JobIntentionDO;
import cn.iocoder.yudao.module.member.service.job.ApiJobService;
import cn.iocoder.yudao.module.member.service.jobintention.JobIntentionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;


@Tag(name = "用户App - 职位")
@RestController
@RequestMapping("/wm/job")
@Validated
public class AppJobController {

    @Resource
    private ApiJobService apiJobService;
    @Resource
    private JobIntentionService jobIntentionService;

    @GetMapping("/jobStatistics")
    @Operation(summary = "首页-当前可报岗位统计")
    public CommonResult<Long> jobStatistics() {
        return success(apiJobService.jobStatistics());
    }

    @GetMapping("/jobAddStatistics")
    @Operation(summary = "首页-24H新增统计")
    public CommonResult<Long> jobAddStatistics() {
        return success(apiJobService.jobAddStatistics());
    }

    @GetMapping("/getJobAddList")
    @Operation(summary = "首页-24H/7天新增岗位列表")
    public CommonResult<PageResult<AppJobRespVO>> getJobAddList(@Valid JobPageReqVO pageReqVO) {
        PageResult<AppJobRespVO> pageResult = apiJobService.getJobAddList(pageReqVO);
        return success(pageResult);
    }


    @GetMapping("/getUserJobIntention")
    @Operation(summary = "首页-获取个人求职意向信息")
    public CommonResult<JobIntentionDO> getUserJobIntention() {
        JobIntentionDO jobIntentionDO = jobIntentionService.getUserJobIntention(getLoginUserId());
        return success(jobIntentionDO);
    }


    @GetMapping("/get")
    @Operation(summary = "获得职位详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<JobRespVO> getJob(@RequestParam("id") Long id) {
        ApiJobDO job = apiJobService.getJob(id);
        return success(BeanUtils.toBean(job, JobRespVO.class));
    }


    @GetMapping("/page")
    @Operation(summary = "获得职位分页")
    public CommonResult<PageResult<AppJobRespVO>> getJobListPage(@Valid JobPageReqVO pageReqVO) {
        PageResult<AppJobRespVO> pageResult = apiJobService.getJobListPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/list")
    @Operation(summary = "关键词搜索")
    public CommonResult<List<Map>> getJobListList(@RequestParam String name) {
        List<Map> pageResult = apiJobService.getJobListList(name);
        return success(pageResult);
    }
}